﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;



namespace seriousWebserver
{
    class Xmlconfigurator
    {
        public void ReadState()
        {
           // XDocument 
            //string data = "<data><test>foo</test><test>foobbbbb</test><bar>123</bar><username>foobar</username></data>";
            XDocument xmlDoc = XDocument.Parse("conf.xml", LoadOptions.PreserveWhitespace);
           // xmlDoc.Parse("conf.xml");
            Dictionary<string, string> dataDictionary = new Dictionary<string, string>();
           // XmlNodeList port = xmlDoc.GetElementsByTagName("port");
            foreach (XElement element in xmlDoc.Descendants().Where(p => p.HasElements == false))
            {
                int keyInt = 0;
                string keyName = element.Name.LocalName;

                while (dataDictionary.ContainsKey(keyName))
                    keyName = element.Name.LocalName + "_" + keyInt++;

                dataDictionary.Add(keyName, element.Value);
            }
           // Console.WriteLine("Address: " + port[0].InnerText);
           // foreach (string s in dataDictionary) Console.WriteLine("Age: " + s);
            foreach (KeyValuePair<string, string> pair in dataDictionary)
            {
                Console.WriteLine("{0}, {1}",
                pair.Key,
                pair.Value);
            }
        }
    }
}

